<template>
  <div class="innerPage">
    <div class="inner-img">
      <div class="img-bg" :style="'background-image:url(' + Contentlist.image + ') '"
        v-if="VideoIndexOf(Contentlist.image)">

      </div>
      <div class="img-bg" :style="'background-image:url(' + Contentlist.image + ') '" v-else>
        <video :src="Contentlist.image" />
      </div>
    </div>
    <!-- <div class="bottom-bg"></div> -->
    <van-row justify="center">
      <van-col span="24" class="inner-title">
        <h1>{{ Contentlist.name }}</h1>
      </van-col>
      <van-col span="24" class="inner-title">
        <div class="Limit-warp">
          <span>限量</span>
          <span>{{ Contentlist.amount }}份</span>
        </div>
      </van-col>
    </van-row>
    <van-row justify="end" class="colletion-authon">
      <van-col span="6" class="left">报名时间</van-col>
      <van-col span="18" class="right">
        <span>{{ Contentlist.startTime }}至{{ Contentlist.endTime ? Contentlist.endTime : "00-00-00" }}</span>
      </van-col>
    </van-row>
    <van-row justify="end" class="colletion-authon">
      <van-col span="6" class="left">抽签时间</van-col>
      <van-col span="18" class="right"><span>{{ Contentlist.endTime ? Contentlist.endTime : "00-00-00" }}</span>
      </van-col>
    </van-row>
    <van-row justify="end" class="colletion-authon" v-if="Contentlist.propType == 0 && Contentlist.assetId">
      <van-col span="6" class="left">合约地址</van-col>
      <van-col span="18" class="right">
        <p>{{ Contentlist.assetId }}</p>
        <img src="../../../assets/image/icon/copids.png" alt="" @click="copy">
      </van-col>
    </van-row>
    <van-row justify="end" class="colletion-authon">
      <van-col span="6" class="left">中签序号</van-col>
      <van-col span="18" class="right"><span>{{ Contentlist.applyCollectionId }}</span></van-col>
    </van-row>

    <div class="Available" v-if="Contentlist.propType == 3">
      <van-row justify="space-between" class="between-warp">
        <van-col span="7" v-for="(item, index) in Available" :key="index">
          <div class="img-warp">
            <img :src="item.image" alt="">
          </div>

        </van-col>
      </van-row>
    </div>
    <van-button type="primary" block class="bind" :loading="loading" @click="look">查看中签名单</van-button>
    <div class="collect-info">
      申购活动详情
    </div>
    <div class="story" v-html="Contentlist.remark"></div>
    <div class="collect-info">
      申购规则
    </div>
    <div class="story">
      <p> 1.藏品申购资格的中签序列数量，会根据藏品发售数量多发放10%-30%；</p>
      <p> 2.用户在进行“申购抽签”时，需要冻结一定数量的积分，中签后积分将被消耗，未中签不消耗积分</p>
      <p>3.用户中签后，方可进入藏品页面购买对应藏品</p>
      <p>4.用户中签后，需及时购买藏品，否则对应藏品售罄后无法使用；</p>
      <p>5.用户中签后，如未在24小时内购买对应藏品，锁消耗积分将退回原账户。</p>
    </div>
    <van-row justify="space-between" class="footer">
      <van-col span="12">
        <span class="price">￥{{ Contentlist.price }}</span>
      </van-col>
      <van-col span="12" class="right">
        <van-button type="primary" @click="Join()"
          v-if="Contentlist.loginUserApply == 0 && Contentlist.registrationStatus == 1" class="buy">
          <span>立即报名</span>
          <span> 已预约{{ Contentlist.applyUserCount }}人</span>
        </van-button>
        <van-button type="primary" v-if="Contentlist.loginUserApply == 1 && Contentlist.registrationStatus == 1"
          class="seing buy">
          <span>已报名</span>
          <span> 已预约{{ Contentlist.applyUserCount }}人</span>
        </van-button>
        <van-button type="primary" v-if="Contentlist.registrationStatus == 0" class="sed">
          <span>活动结束</span>

        </van-button>
      </van-col>
    </van-row>
    <van-popup v-model:show="popupshow">
      <div class="gift-warp">
        <van-icon name="cross" @click="popupshow = false" color="#999" />
        <van-row justify="space-around" class="Winprize">
          <van-col span="6">
            <span>中签序列</span>
          </van-col>
          <van-col span="6"> <span>中签人</span></van-col>
        </van-row>
        <div class="winlist">
          <van-row justify="space-between" v-for="(item, index) in drawList" :key="index">
            <van-col span="10" class="left">{{ item.userApplyLogId }}</van-col>
            <van-col span="14" class="right">{{ formatPhoneNumber(item.userMobile) }}</van-col>
          </van-row>
          <!-- <van-row justify="space-between">
            <van-col span="10">346279</van-col>
            <van-col span="14" class="right">177****6065 DRTJJ</van-col>
          </van-row> -->

          <div class="more">滑动查看更多</div>
        </div>
      </div>
    </van-popup>
    <Pwdwarp ref="PwdShow" :paydata="paydata" @updata:load="onLoad" />
  </div>
</template>
<script>
import { reactive, computed, onMounted, defineComponent, onBeforeMount, ref, watch } from 'vue'
import Clipboard from 'clipboard';
import useClipboard from 'vue-clipboard3'
import { useStore } from "vuex";
import { useRouter } from "vue-router"
import { VideoIndexOf, formatPhoneNumber } from "@/utils/phone";
import Pwdwarp from "@/components/pwd.vue";
import { applygetInfo, drawIpage, participateDraw } from "@/api/public";
import { Toast, ImagePreview } from "vant";
import video from "@/components/video.vue";
export default {
  components: {
    Pwdwarp, video
  },
  setup(props) {
    const store = useStore();
    const router = useRouter()
    const popupshow = ref(false)
    const PwdShow = ref(null)
    const { toClipboard } = useClipboard()
    const Contentlist = ref({})
    const paydata = ref({
      id: router.currentRoute.value.query.id,
      type: "5"
    })
    const onLoad = async () => {
      Toast.loading({
        message: '数据加载中...',
        forbidClick: true,
      });

      const data = { applyId: router.currentRoute.value.query.id }
      console.log(router.currentRoute.value.query.id)

      const res = await applygetInfo(data)
      if (res.data.success) {
        Toast.clear()
        Contentlist.value = res.data.data
        console.log(Contentlist.value)
      }


    }
    const loading = ref(false)
    const drawList = ref({})
    const look = async () => {
      // loading.value = true
      popupshow.value = true
    }
    const copy = async () => {
      try {
        await toClipboard(Contentlist.value.assetId)
        Toast("复制成功")
      } catch (e) {
        console.error(e)
      }
    }
    const Join = () => {
      paydata.id = Contentlist.value.applyCollectionId
      console.log(paydata.value, Contentlist.value.applyCollectionId)
      PwdShow.value.pwdopen = true
      // const data = {
      //   applyId: Contentlist.value.applyCollectionId
      // }

      // participateDraw(data).then(res => {
      //   if (res.data.success) {
      //     Toast("报名成功")
      //     onLoad()
      //   }
      // })
    }

    onMounted(() => {
      onLoad()
      drawIpage({ applyId: router.currentRoute.value.query.id }).then(res => {
        console.log(res.data.data.records)
        drawList.value = res.data.data
      })
      const data = { id: router.currentRoute.value.query.id }
    })
    return {
      Contentlist, onLoad, popupshow, copy, Join, look, loading, drawList, VideoIndexOf, paydata, PwdShow, formatPhoneNumber
    }
  }
}
</script>
<style lang="less" scoped>
.more {
  text-align: center;
}

.innerPage {
  .bind {
    width: 709px;
    height: 88px;
    background: linear-gradient(-90deg, #37dc6d, #34d1f9);
    border-radius: 44px;
    border: none;
    font-size: 36px;
    font-family: Source Han Sans CN;
    font-weight: bold;
    color: #ffffff;
    margin: 40px 20px;
    display: block;
  }

  padding-bottom: 148px;

  .inner-img {
    position: relative;
    width: 100%;
    height: 648px;
    // background: linear-gradient(0deg, #161718, #4b4c4d);
    // border: 1px solid #ffffff;
    // border-radius: 80px;
    margin: 80px auto 20px;
    overflow: hidden;

    .img-bg {
      // border-radius: 80px;
      // width: 648px;
      height: 648px;
      background-size: cover;
      // margin: 100px auto;
      position: relative;
      background-position: center;
      background-repeat: no-repeat;

      .img-status {
        right: 0px;
        display: flex;
        justify-content: center;
        align-items: center;
        color: white;
        width: 200px;
        height: 200px;
        background-size: contain !important;
        background-repeat: no-repeat;
        position: absolute;
        background: url('../../../assets/image/status.png');
      }
    }
  }

  .bottom-bg {
    background: url('../../../assets/image/bottom.png');
    width: 660px;
    height: 220px;
    background-size: cover;
    margin: 0px auto;
  }

  .inner-title {
    text-align: center;

    h1 {
      font-size: 46px;
      font-family: Source Han Sans CN;
      font-weight: 400;
      color: #f8f8f8;
      line-height: 103px;
      margin: 0px;
    }
  }

  .Limit-warp {
    span {
      font-size: 26px;
      font-family: Source Han Sans CN;
      font-weight: 400;
      line-height: 48px;
    }

    span:nth-child(1) {
      color: #444442;
      font-size: 26px;
      font-family: Source Han Sans CN;
      font-weight: 400;
      background: #f3e3bb;
      border-radius: 4px 0px 0px 4px;
      padding: 3px 12px;
    }

    span:nth-child(2) {
      padding: 3px 12px;
      background: #444442;
      border-radius: 4px;
      font-size: 26px;
      font-family: Source Han Sans CN;
      font-weight: 400;
      color: #f3e3bb;
      line-height: 48px;
    }
  }

  .colletion-authon {
    // .left {
    //   text-align: left;
    // }
    padding: 0px 18px;
    font-size: 34px;
    font-family: Source Han Sans CN;
    font-weight: 400;
    color: #ffffff;
    line-height: 140px;
    margin: 30px 20px 0px;
    height: 120px;
    background: #282a2c;
    border: 1px solid #999;
    border-bottom: 0px;
    box-shadow: 0px 2px 30px 0px rgba(0, 0, 0, 0.35);
    border-radius: 20px;

    .right {
      display: flex;
      align-items: center;
      justify-content: flex-end;
      text-align: right;

      p {
        width: 80%;
        overflow: hidden;
        text-overflow: ellipsis;
      }

      img {
        width: 40px;
        margin-left: 20px;
      }

      text-align: right;

      span {
        text-align: center;
        font-size: 20px;
        font-family: Source Han Sans CN;
        font-weight: 400;
        color: #fefefe;
        background: linear-gradient(-90deg, #37dc6d 0%, #34d1f9 100%);
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
      }
    }
  }

  .collect-info {
    z-index: 1;
    margin-top: 50px;
    font-size: 36px;
    font-family: Source Han Sans CN;
    font-weight: 400;
    color: #f8f8f8;
    margin-left: 20px;
    padding-left: 40px;
    position: relative;
  }

  .collect-info::after {
    opacity: 0.8;
    z-index: -1;
    background-size: 100% 100%;
    width: 70px;
    height: 60px;
    top: -10px;
    left: 0;
    position: absolute;
    content: '';
    background-image: url('../../../assets/image/point.png');
  }

  .story {
    background: #282a2c;
    border: 1px solid #999;
    box-shadow: 0px 2px 16px 0px rgba(0, 0, 0, 0.35);
    border-radius: 20px;
    margin: 30px 30px;
    padding: 60px 30px;
    font-size: 28px;
    font-family: Source Han Sans CN;
    font-weight: 400;
    color: #ffffff;
    line-height: 48px;

    /deep/ img {
      width: 100%;
    }
  }

  .footer {
    width: 750px;
    padding: 30px 0px;
    background: #282a2c;
    position: fixed;
    bottom: 0px;
    z-index: 999;
    display: flex;
    align-items: center;

    .price {
      font-size: 46px;
      font-family: Source Han Sans CN;
      font-weight: bold;
      color: #f8f8f8;
      margin-left: 50px;
    }

    .right {
      padding-right: 20px;
      text-align: right;
      display: flex;
      justify-content: flex-end;
      // &:deep(.van-button) {

      // }
      .sed {
        border: none;
        border-radius: 62px;
        width: 256px;
        height: 74px;
        background: #7d8184;
        border-radius: 32px;

        span {
          display: block;
          font-size: 28px;
          font-family: Source Han Sans CN;
          font-weight: 400;
          color: #ffffff;
          line-height: 26px;
        }
      }

      .buy {
        border: none;
        background: linear-gradient(-90deg, #37dc6d, #34d1f9);
        border-radius: 62px;
        width: 256px;
        height: 74px;

        span {
          display: block;
        }
      }
    }
  }
}

&:deep(.van-popup) {
  background: #000 !important;
}

.gift-warp {
  .right {
    text-align: right;
  }

  .winlist {
    line-height: 50px;
    padding: 30px;
    margin: 30px 40px;
    height: 526px;
    background: linear-gradient(0deg, #161718, #4b4c4d);
    border: 1px solid #999;
    border-radius: 10px;
    // margin: 30px auto;
    font-size: 26px;
    font-family: Source Han Sans CN;
    font-weight: 400;
    color: #ffffff;
    overflow-y: scroll;

    .left {
      padding-left: 60px;
    }
  }

  .Winprize {
    text-align: center;
    padding-top: 20px;

    span {
      height: 29px;
      font-size: 30px;
      font-family: Source Han Sans CN;
      font-weight: bold;
      color: #ffffff;
      background: linear-gradient(-90deg, #37dc6d 0%, #34d1f9 100%);
      -webkit-background-clip: text;
      -webkit-text-fill-color: transparent;
    }
  }

  padding-top: 50px;

  i {
    top: 20px;
    right: 20px;
    position: absolute;
    color: #fefefe;
    font-size: 60px;
  }

  img {
    display: block;
    width: 625px;
    height: 415px;
    margin: 50px auto 0px;
  }

  .box-btn {
    font-size: 32px;
    display: block;
    border: none;
    width: 448px;
    height: 80px;
    background: linear-gradient(-90deg, #37dc6d, #34d1f9);
    margin: 20px auto;
  }

  h1 {
    text-align: center;
    font-size: 48px;
    font-family: Source Han Sans CN;
    font-weight: bold;
    color: #f3e3bb;
    line-height: 42px;
    margin: 40px 0px;
  }

  width: 688px;
  height: 727px;
  background-image: url('../../../assets/image/giftbg.png');
  background-size: 100% 100%;
}
</style>